"""
构造一个列表或者字典的子集
用股票价格大于100元的股票构造一个新的字典
"""
from math import sqrt


def main():
    prices = {
        'AAPL': 191.88,
        'GOOG': 1186.96,
        'IBM': 149.24,
        'ORCL': 48.44,
        'ACN': 166.89,
        'FB': 208.09,
        'SYMC': 21.29
    }

    prices_list = list(prices.values())
    print(prices_list)
    print(list(map(lambda x: sqrt(x), prices_list)))
    print([sqrt(x) for x in prices_list])
    # 按照股票价格从高到低对字典元素进行排序
    new_dict = dict(sorted(zip(prices.values(), prices.keys()), reverse=True))
    print(dict(zip(new_dict.values(), new_dict.keys())))

    # filter map
    prices_gt100 = {key: value for key, value in prices.items()
                    if value > 100}
    print(prices_gt100)

    """
    prices_gt100 = {}
    for elem in filter(lambda x: prices[x] > 100, prices):
        prices_gt100[elem] = prices[elem]
    print(prices_gt100)
    """

    """
    prices_gt100 = {}
    for key, value in prices.items():
        if value > 100:
            prices_gt100[key] = value
    print(prices_gt100)
    """


# LEGB
# Local --> Embedded --> Global --> Built-in
if __name__ == '__main__':
    main()
